﻿#region

using System;
using MediaSage.Lib.Utilities;
using NHibernate;
using NHibernate.Criterion;

#endregion

namespace MediaSage.Lib.Database
{
    public class FileSystemEntity : DatabaseObject
    {
        #region Properties

        public virtual string directory { get; set; }

        public virtual Guid ID { get; protected set; }

        public virtual DateTime? lastScan { get; set; }

        public virtual bool recurse { get; set; }

        #endregion Properties

        public override void Save()
        {
            ISession session = DBUtil.GetSession();
            using (session.BeginTransaction())
            {
                var dbFS =
                    session.CreateCriteria(typeof(FileSystemEntity)).Add(Restrictions.Eq("directory", directory)).
                        UniqueResult<FileSystemEntity>();
                if (dbFS != null)
                {
                    // There really is no merging FileSystemEntities, as this is a configuration item
                    ID = dbFS.ID;
                }
            }
            base.Save();
        }
    }
}